import {
  Controller,
  Get,
  Post,
  Redirect,
  HttpCode,
  Header,
  // Inject,
  Req,
  Request,
  Query,
  Session,
  Params,
  Body,
  Res,
  Response,
  Next,
} from './@nestjs/common';
import type { Request as ExpressRequest, Response as ExpressResponse, NextFunction } from 'express';

import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(
    private appService: AppService,
    // @Inject('token') private appService: AppService,
  ) {}

  @Get()
  @Redirect('https://www.baidu.com', 302)
  getHello(): string {
    return 'Hello World11';
  }

  @Get('hello2')
  getHello2(@Req() req: ExpressRequest, @Request() request: ExpressRequest): string {
    console.log(req.path);
    console.log(request.method);
    return this.appService.getHello2();
  }

  @Get('hello3')
  @Header('Content-Type', 'application/x-www-form-urlencoded')
  getHello3(
    @Query() query: any,
    @Query<string>('id') id: string,
    @Session() session: any,
    @Params() params: any,
    @Next() next: NextFunction,
  ) {
    console.log(query);
    console.log('🚀 ~ getHello3 ~ query: ', query);
    console.log(id);
    console.log(session);
    console.log(params);
    next();
    return '111';
  }

  @Post('hello4')
  @HttpCode(201)
  getHello4(
    @Body() body: any,
    @Res() res: ExpressResponse,
    @Response({ passthrough: true }) response: ExpressResponse,
  ): string {
    console.log(response);
    console.log('🚀 ~ getHello4 ~ body: ', body);
    console.log(res);
    return `666`;
  }
}
